﻿using System.Web.UI.WebControls;
using System.IO;
using System.Text.RegularExpressions;
using System;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Text;
using SalePartial.Utility;


namespace XunPan.Web.Globals
{

    public class GlobalUtility
    {
        //*********************************************************************
        //
        // AllowHtml Enumeration
        //
        // Possible values for AllowHtml    
        //
        //*********************************************************************

        public enum AllowHtml
        {
            None = 0,
            Limited = 1,
            Full = 2
        }
        //AllowHtml


        public static bool IsValidGuid(string strIn)
        {
            // Return true if strIn is in valid e-mail format.
            return (strIn != null) && (Regex.IsMatch(strIn, "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$", RegexOptions.IgnoreCase));
        }

        /// <summary>
        /// Serialze object to string
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string SerializedAsString(object target)
        {

            try
            {
                LosFormatter formatter = new LosFormatter();
                StringWriter writer = new StringWriter();
                formatter.Serialize(writer, target);

                return writer.ToString();
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        /// <summary>
        /// Deserialze the string to object
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string DeserialzedFromString(string data)
        {

            try
            {
                LosFormatter formatter = new LosFormatter();
                return formatter.Deserialize(data).ToString();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        // *********************************************************************
        //  Text Formatting Methods用于文本格式化的几个方法
        // *********************************************************************
        public static string ParseCurrencyCode(string code, string xmlfile)
        {
            string name = "";
            string filepath = null;

            if (string.IsNullOrEmpty(xmlfile))
            {
                filepath = "~/app_data/lib/Currency.xml";
            }
            else
            {
                filepath = xmlfile;
            }
            filepath = HttpContext.Current.Server.MapPath(filepath);
            if (File.Exists(filepath))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(filepath);
                foreach (DataTable dt in ds.Tables)
                {
                    DataView dv = dt.DefaultView;

                    dv.RowFilter = "Value = '" + code + "'";
                    if (dv.Count > 0)
                    {
                        name = dv[0]["Name"].ToString();
                        return name;
                    }
                }


            }

            return name;
        }


        public static string ParseProcessCode(string code, int type, string xmlfile)
        {
            string names = "";
            string filepath = null;
            switch (type)
            {
                case 1:
                    //零部件
                    if (string.IsNullOrEmpty(xmlfile))
                    {
                        filepath = "~/app_data/lib/warecube.xml";
                    }
                    else
                    {
                        filepath = xmlfile;
                    }
                    break;
                case 0:
                    //加工工艺
                    if (string.IsNullOrEmpty(xmlfile))
                    {
                        filepath = "~/app_data/lib/mfgprocess.xml";
                    }
                    else
                    {
                        filepath = xmlfile;
                    }

                    break;
                default:
                    return names;
            }


            filepath = HttpContext.Current.Server.MapPath(filepath);
            if (File.Exists(filepath))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(filepath);
                foreach (DataTable dt in ds.Tables)
                {
                    DataView dv = dt.DefaultView;
                    string[] catas = code.Split('0');
                    for (int i = 0; i <= catas.Length - 1; i++)
                    {
                        dv.RowFilter = "key = '" + catas[i] + "'";
                        if (dv.Count > 0)
                        {
                            names = names + dv[0]["title"];
                            if (i < catas.Length - 1)
                            {
                                names = names + " / ";
                            }
                        }
                    }
                }

                return names;
            }

            return names;
        }



        //'*********************************************************************
        //'
        //' FormatText Method
        //' 方法：文本格式化
        //' 
        //'*********************************************************************


        //public static string FormatText(AllowHtml useHtml, int moduleID, string text)
        //{
        //    // Return when null
        //    if (text == null)
        //    {
        //        return string.Empty;
        //    }

        //    // if no HTML allowed, HTML Encode 如果不允许HTML格式，先进行HTML编码
        //    if (useHtml == AllowHtml.None)
        //    {
        //        //普通文本
        //        text = FormatPlainText(text);
        //    }
        //    else
        //    {
        //        //超链接编码
        //        text = EnsureSafeAnchors(text);

        //        if (useHtml == AllowHtml.Full)
        //        {
        //            text = HttpUtility.HtmlDecode(text);
        //        }
        //        else
        //        {
        //            text = FormatLimitedHtmlText(text);
        //        }
        //    }
        //    // Apply transformations实施文本格式转换
        //    text = ApplyTransformations(moduleID, text);

        //    return text;
        //}
        //FormatText




        //*********************************************************************
        //
        // FormatPlainText Method
        // 方法：普通文本格式化
        // This method is used for formatting all text that SHOULD NOT
        // contain HTML. This method 
        // HtmlEncodes the text and adds line breaks. 
        // 描述：该方法可以对所有的不包含html的文本进行htmlencodes，并添加行分隔符
        // 
        //*********************************************************************
        //public static string FormatPlainText(string text)
        //{
        //    // HTML encode the text
        //    text = HttpUtility.HtmlEncode(text);

        //    // Add line breaks 
        //    text = Regex.Replace(text, Constants.vbLf + Constants.vbLf, "<p>");
        //    text = Regex.Replace(text, Constants.vbLf, "<br>");

        //    return text;
        //}
        //FormatPlainText


        //*********************************************************************
        //
        // FormatPlainText Method
        // 方法：普通文本格式化
        // This method is used for formatting all text that SHOULD NOT
        // contain HTML. This method 
        // HtmlEncodes the text and adds line breaks. 
        // 描述：该方法可以对所有的不包含html的文本进行htmlencodes，并添加行分隔符
        // 
        //*********************************************************************
        public static string FormatLimitedHtmlText(string text)
        {

            // Add line breaks 
            text = Regex.Replace(text, "&lt;a&gt;", "<a>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/a&gt;", "</a>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;b&gt;", "<b>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/b&gt;", "</b>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;br&gt;", "<br>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;br /&gt;", "<br />", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;font&gt;", "<font>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/font&gt;", "</font>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;i&gt;", "<i>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/i&gt;", "</i>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;li&gt;", "<li>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/li&gt;", "</li>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;ol&gt;", "<ol>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/ol&gt;", "</ol>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;p&gt;", "<p>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/p&gt;", "</p>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;s&gt;", "<s>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/s&gt;", "</s>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;span&gt;", "<span>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/span&gt;", "</span>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;strike&gt;", "<strike>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/strike&gt;", "</strike>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;strong&gt;", "<strong>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/strong&gt;", "</strong>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;table&gt;", "<table>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/table&gt;", "</table>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;thead&gt;", "<thead>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/thead&gt;", "</thead>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;tfoot&gt;", "<tfoot>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/tfoot&gt;", "</tfoot>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;tbody&gt;", "<tbody>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/tbody&gt;", "</tbody>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;tr&gt;", "<tr>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/tr&gt;", "</tr>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;td&gt;", "<td>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/td&gt;", "</td>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;th&gt;", "<th>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/th&gt;", "</th>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;u&gt;", "<u>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/u&gt;", "</u>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;ul&gt;", "<ul>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&lt;/ul&gt;", "</ul>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&amp;", "&", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            text = Regex.Replace(text, "&quot;", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);


            return text;
        }
        //FormatPlainText



        //'*********************************************************************
        //'
        //' ApplyTransformations Method
        //' 方法：实施文本格式转换
        //' This method applies each transformation to a string
        //' of text. The transformations are precalculated when
        //' the sections are first loaded in the ModuleUtility
        //' class. 
        //' 描述：该方法将每一个转换引用为文本格式的string
        //' 当sectionutility类第一次加载社区模块section时，会预处理相应的转换
        //'*********************************************************************
        public static string ApplyTransformations(int moduleID, string text)
        {
            // Get the section transformation

            string[] splitTrans = Regex.Split("Transformations", "/n");

            int i = 0;
            for (i = 0; i <= splitTrans.Length - 2; i += 2)
            {
                try
                {
                    text = Regex.Replace(text, splitTrans[i], splitTrans[(i + 1)], RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Multiline);
                }
                catch
                {
                    // we don't do anything in the catch because we
                }
            }
            // are just hiding errors in the transformations               
            return text;
        }
        //ApplyTransformations





        //*********************************************************************
        //
        // EnsureSafeAnchors Method
        // 方法：验证超链接的目的URL格式，并进行超链接格式转换
        //*********************************************************************


        //private static string EnsureSafeAnchors(string stringToTransform)
        //{
        //    MatchCollection matchs = default(MatchCollection);

        //    // Ensure we have safe anchors
        //    //URL格式验证
        //    matchs = Regex.Matches(stringToTransform, "&lt;a.href=(&quot;)?(?<url>http://((.|\\n)*?))(&quot;)?&gt;(?<target>((.|\\n)*?))&lt;/a&gt;", RegexOptions.IgnoreCase | RegexOptions.Compiled);

        //    //Match m = default(Match);
        //    foreach (Match m in matchs)
        //    {
        //        //转换为超链接
        //        stringToTransform = stringToTransform.Replace(m.ToString(), "<a target=\"_new\" href=\"" + m.Groups["url"].ToString() + "\">" + m.Groups("target").ToString() + "</a>");
        //    }

        //    return stringToTransform;
        //}
        //'EnsureSafeAnchors


        //*********************************************************************
        //
        // TruncateWithEllipsis Method
        // 方法：截取字符串并加省略号.
        // This method shortens a string to a certain length and
        // adds ... when the string is longer than a specified
        // maximum length.
        // 描述：按照一定的长度将字符串截短，如果字符串长度小于等于规定长度，这不做处理
        // 否则将添加省略号...
        //*********************************************************************
        public static string TruncateWithEllipsis(string text, int length)
        {
            if (text.Length > length)
            {
                text = text.Substring(0, length) + "...";
            }
            return text;
        }
        //TruncateWithEllipsis




        //*********************************************************************
        //
        // Truncate Method
        // 方法：截取字符串
        // This method chops off the end of a string when the
        // string is longer than a maximum length.
        // 描述：该方法类上，当字符串长度大于规定长度时不添加省略号...
        //*********************************************************************
        public static string Truncate(string text, int length)
        {
            if (text.Length > length)
            {
                text = text.Substring(0, length);
            }
            return text;
        }
        //Truncate



        //*********************************************************************
        //
        // StripTags Method
        // 方法：剔除html标记
        // This method strips all tags from a string (good for removing all
        // HTML.
        // 描述：将字符串中所有的html标记剔除
        //*********************************************************************
        public static string StripTags(string text)
        {
            text = Regex.Replace(text, "&nbsp;", "", RegexOptions.IgnoreCase);
            return Regex.Replace(text, "<.+?>", "", RegexOptions.Singleline);
        }
        //StripTags     



        // *********************************************************************
        //  Global Validation Methods 全局校验方法
        // *********************************************************************


        //*********************************************************************
        //
        // ValidateLength Method
        // 方法：验证字符串长度
        // This method associates a client-side and server-side
        // function with a custom validator to check whether a
        // string of text is less than 300 characters.
        // 描述：该方法结合客户端验证和服务端验证，验证字符串长度不超过300
        //*********************************************************************

        public static void ValidateLength(System.Web.UI.WebControls.CustomValidator validator, string scriptName)
        {
            StringBuilder builder = new StringBuilder();

            // Form the script that is to be registered at client side.
            builder.Append("<script language=JavaScript>" + "/n");
            builder.AppendFormat("function {0}(s, e) {{" + "/n", scriptName);
            builder.AppendFormat("if (e.Value.length > 300)" + "/n");
            builder.Append("  e.IsValid = false;" + "/n");
            builder.Append("else" + "/n");
            builder.Append("  e.IsValid = true;" + "/n");
            builder.Append("}</script>");

            if (!validator.Page.ClientScript.IsClientScriptBlockRegistered(scriptName))
            {
                validator.Page.ClientScript.RegisterClientScriptBlock(validator.Page.GetType(), scriptName, builder.ToString());
            }
            // Associate client-side validation
            validator.ClientValidationFunction = scriptName;
            // Add server-side validation
            validator.ServerValidate += ServerValidateLength;
        }
        //ValidateLength



        //*********************************************************************
        //
        // ServerValidateLength Method
        // 方法：服务器端验证字符串长度
        // Server-side validation method used with a custom validator
        // to check whether a string is less than a specified length.
        // 描述：该方法为服务端验证字符串长度不超过300
        //*********************************************************************
        public static void ServerValidateLength(Object s, ServerValidateEventArgs e)
        {
            if (e.Value.Length > 300)
            {
                e.IsValid = false;
            }
            else
            {
                e.IsValid = true;
            }
        }
        //ServerValidateLength





        // *********************************************************************
        //  Path Manipulation Methods 路径处理的一些方法
        // *********************************************************************

        //*********************************************************************
        //
        // ResolveAbsoluteUrl Method
        // 方法：转换为绝对虚拟路径
        // This method translates a relative path into an
        // absolute path.
        // 描述：该方法将相对URL路径转换为绝对URL路径
        //*********************************************************************

        //需要将站点primary domin存入web.config文件的section 或者自定义配置节点，并在此处读入节点置

        public static string ResolveAbsoluteUrl(string Url)
        {
            if (HttpContext.Current.Request.IsSecureConnection)
            {
                //若为可靠站点
                return "https://" + GlobalSetting.DomainName + Url;
            }
            else
            {
                //否则
                return "http://" + GlobalSetting.DomainName + Url;
            }
        }


        /// <summary>
        /// 获取应用程序根的虚拟路径，并使用波形符使相对路径成为根的虚拟路径
        /// </summary>
        /// <param name="relateivepath"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string ResolveAppRelativeVirtualPath(string relateivepath)
        {
            if (relateivepath.StartsWith("~"))
            {
                return relateivepath;
            }
            else
            {
                string path = GetRequestFolderPath(HttpContext.Current.Request.Path);

                path = path.Replace(HttpContext.Current.Request.ApplicationPath, "~") + relateivepath;

                return path;
            }

        }






        //*********************************************************************
        //
        // CacheKey Method
        // 方法：缓存键值
        // Generates a community relative cache key so that 
        // cached data can be partitioned from different 
        // communities.
        // 描述：生成社区相对的cache key，以便标示不同社区的cache数据
        //*********************************************************************
        public static string CacheKey(string key)
        {
            return GlobalSetting.SiteID.ToString() + key;
        }
        //CacheKey

        //*********************************************************************
        //
        // ResolveBase Method
        // 方法：转换为绝对物理路径
        // Adds the base application path to a relative path.
        // 描述：将相对路径转换为虚拟应用程序的绝对路径
        //*********************************************************************
        /// <summary> 
        /// 方法：解析css文件的相对
        /// </summary> 
        /// <param name="cssFilename">css文件名</param> 
        public static string ResolveCSSPath(string cssFilename)
        {
            string requestPath = HttpContext.Current.Request.FilePath;
            string fullpath = HttpContext.Current.Request.PathInfo;
            string path = HttpContext.Current.Request.Path;
            string patha = HttpContext.Current.Request.PhysicalApplicationPath;
            string pp = HttpContext.Current.Request.PhysicalPath;
            string pagename = GetPageName(requestPath);
            string pathonly = requestPath.Remove(requestPath.Length - pagename.Length);

            return pathonly + "/" + cssFilename;
        }
        //ResolveBase


        //*********************************************************************
        //
        // ResolveBase Method
        // 方法：转换为绝对物理路径
        // Adds the base application path to a relative path.
        // 描述：将相对路径转换为虚拟应用程序的绝对路径
        //*********************************************************************

        /// <summary> 
        /// 方法：转换为绝对物理路径
        /// 描述：将相对路径转换为虚拟应用程序的绝对路径
        /// </summary> 
        /// <param name="relativePath">相对路径</param> 
        public static string ResolveBase(string relativePath)
        {
            return AppPath + "/" + relativePath;
        }




        //*********************************************************************
        //
        // AppPath Property
        // 属性：应用程序路径
        // Represents the path of the current application.
        // 描述：目前虚拟应用程序所在的路径
        //*********************************************************************

        public static string AppPath
        {
            get
            {
                if (HttpContext.Current.Request.ApplicationPath == "/")
                {
                    return string.Empty;
                }
                return HttpContext.Current.Request.ApplicationPath;
            }
        }



        //*********************************************************************
        //
        // GetPageName Method
        // 方法：获取页面名称
        // Removes everything from a request except for the page
        // name.
        // 描述：从请求路径中提取页面名称
        //*********************************************************************
        public static string GetPageName(string requestPath)
        {
            // Remove query string
            if (requestPath.IndexOf('?') != -1)
            {
                requestPath = requestPath.Substring(0, requestPath.IndexOf('?'));
            }
            // Remove base path
            return requestPath.Remove(0, requestPath.LastIndexOf("/"));
        }
        //GetPageName



        /// <summary>
        /// 获取请求路径(不带页面名称和查询字符串)
        /// </summary>
        /// <param name="requestPath">请求路径</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string GetRequestFolderPath(string requestPath)
        {
            // Remove page name
            int slashIndex = requestPath.LastIndexOf("/");
            if (slashIndex < requestPath.Length)
            {
                requestPath = requestPath.Remove(slashIndex + 1, requestPath.Length - (slashIndex + 1));
            }
            return requestPath;

        }



        /// <summary>
        /// 获取应用程序根路径下第一个子文件夹名称
        /// 如应用程序根路径为/ntpart
        /// 则输入/ntpart/user/login/reg.aspx则返回user
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string GetFirstFolderNameFromModulePath(string path)
        {


            string folderPattern = "/\\w+/";
            string targetFolder = GlobalUtility.GetRequestFolderPath(path).ToLower();

            if (GlobalUtility.AppPath.Length > 0)
            {
                targetFolder = targetFolder.Replace(GlobalUtility.AppPath.ToLower(), "");
            }

            if (Regex.IsMatch(targetFolder, folderPattern))
            {
                targetFolder = Regex.Match(targetFolder, folderPattern).Value;
            }
            targetFolder = targetFolder.Replace("/", "");

            return targetFolder;

        }
        //GetModulePath


        //*********************************************************************
        //
        // RemovePathInfo Method
        // 方法：移除PathInfo
        // Removes the extended information after a page path.
        // For example, removes the Web service information after
        // the .asmx file name.
        // 描述：移除请求路径页面后所附加的信息,例如Http://www.contoso.com/virdir/page.aspx?cid=1&uid=1
        // 移除?cid=1&uid=1
        //*********************************************************************
        public static string RemovePathInfo(string requestPath)
        {
            string _pathInfo = HttpContext.Current.Request.PathInfo;
            if (_pathInfo.Length == 0)
            {
                return requestPath;
            }
            return requestPath.Substring(0, requestPath.Length - _pathInfo.Length);
        }
        //RemovePathInfo



        //*********************************************************************
        //
        // CalculatePath Method
        // 方法：计算路径
        // This method takes a path and replaces the file
        // name with a new file name.
        // 描述：该方法根据页面名称计算新的页面路径
        //*********************************************************************

        //需要改写该函数，对相应的模块进行不同的计算方法，暂时先将其改作标准件库模块的计算路径方法

        public static string CalculateFullUrl(string basePath)
        {


            string fullUrl = ResolveAbsoluteUrl(basePath);

            return fullUrl;
        }
        //CalculatePath




        //*********************************************************************
        //
        // ForceLogin Method
        // 方法：强制登录
        // Redirects the user to the Login page.
        // 描述：将页面重定向至登录页面
        //*********************************************************************
        public static void ForceLogin()
        {
            HttpContext Context = HttpContext.Current;
            Context.Response.Redirect(string.Format("{0}?ReturnUrl={1}", "~/Login/login.aspx", Context.Server.UrlEncode(Context.Request.RawUrl)));
        }
        //ForceLogin




        //*********************************************************************
        //
        // CalculatePath Method
        // 方法：计算路径
        // This method takes a path and replaces the file
        // name with a new file name.
        // 描述：该方法根据页面名称计算新的页面路径
        //*********************************************************************

        //需要改写该函数，对相应的模块进行不同的计算方法，暂时先将其改作标准件库模块的计算路径方法
        public static string CalculatePath(string pageName)
        {
            //string rawUrl = HttpContext.Current.Request.RawUrl;
            //从模块信息中取得路径
            string _rawUrl = "CType(HttpContext.Current.Items('ModuleInfo'), ModuleInfo).Path";
            //去除去的路径中的旧页面名称后，得到基本路径
            string basePath = _rawUrl.Remove(_rawUrl.LastIndexOf("/"), _rawUrl.Length - _rawUrl.LastIndexOf("/"));
            return basePath + "/" + pageName;
        }
        //CalculatePath



        //*********************************************************************
        //
        // IsNumeric Method
        // 方法：数字验证
        // Since C# doesn't have an IsNumeric function,
        // we have to use our own.
        // 描述：注意V.NET中验证字符串是否为数字式的方法，利用TRY CATCH 
        // 捕捉PARSE方法的异常
        //*********************************************************************
        public static bool IsNumeric(string strInteger)
        {
            try
            {
                int intTemp = Int32.Parse(strInteger);
                return true;
            }
            catch
            {
                return false;
            }
        }
        //IsNumeric
    }
}
